//
//  SKFirstView.m
//  SKaURobot
//
//  Created by cdong on 16/2/19.
//  Copyright © 2016年 cdong. All rights reserved.
//

#import "SKFirstView.h"
#import "THCircularProgressView.h"

@implementation SKFirstView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUpView];
    }
    return self;
}

- (void)setUpView{
    self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg_login"]];
    CGFloat width = self.frame.size.width;
    CGFloat radius = floor(310*matchW/2);
    THCircularProgressView *outProgressView = [[THCircularProgressView alloc]initWithCenter:CGPointMake(width/2, 88*matchH + radius - 21*matchH) radius:radius+1 lineWidth:1 progressMode:(THProgressModeDeplete) progressColor:[RGBColorEncapsulation colorWithRGB:0x494949 alpha:1] progressBackgroundMode:(THProgressBackgroundModeCircumference) progressBackgroundColor:[RGBColorEncapsulation colorWithRGB:0x494949 alpha:1] percentage:1];
    [self addSubview:outProgressView];
    
    self.robotImageV = [[UIImageView alloc]initWithFrame:CGRectMake(52*matchW, 88*matchH, 271*matchW, 271*matchW)];
    self.robotImageV.image = [UIImage imageNamed:@"pic_rabbit_a"];
    [self addSubview:self.robotImageV];
    
    self.robotNameL = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.robotImageV.frame) + 19.5*matchH + 32*matchH, self.frame.size.width, 30*matchH)];
    self.robotNameL.text = @"阿u兔智";
    self.robotNameL.textAlignment = NSTextAlignmentCenter;
    self.robotNameL.textColor = [RGBColorEncapsulation colorWithRGB:0x828182 alpha:1];
    self.robotNameL.font = [UIFont systemFontOfSize:24*matchW];
    [self addSubview:self.robotNameL];
    
    self.robotStateL = [[UILabel alloc]initWithFrame:CGRectMake((self.frame.size.width - 266*matchW)/2 + 10*matchW, CGRectGetMaxY(self.robotNameL.frame), 266*matchW, 21*matchH)];
    self.robotStateL.text = @"[未连接，请尽快将手机与机器人连接！]";
    self.robotStateL.font = [UIFont systemFontOfSize:14*matchW];
    self.robotStateL.textAlignment = NSTextAlignmentCenter;
    self.robotStateL.textColor = [RGBColorEncapsulation colorWithRGB:0x0ac8c6 alpha:1];
    [self addSubview:self.robotStateL];
    
    self.operationBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.operationBtn.frame = CGRectMake(147.5*matchW, CGRectGetMaxY(self.robotStateL.frame) + 38*matchH, 80*matchW, 80*matchH);
    [self.operationBtn setTitle:@"连接" forState:UIControlStateNormal];
    [self.operationBtn setTitleColor:[RGBColorEncapsulation colorWithRGB:0xffffff alpha:1] forState:UIControlStateNormal];
    self.operationBtn.titleLabel.font = [UIFont systemFontOfSize:20];
    [self.operationBtn setBackgroundImage:[UIImage imageNamed:@"bg_connect"] forState:UIControlStateNormal];
    [self addSubview:self.operationBtn];
}

- (void)UI{
    self.robotStateL = [[UILabel alloc]initWithFrame:CGRectMake((self.frame.size.width - 57*matchW)/2 + 10*matchW, CGRectGetMaxY(self.robotNameL.frame), 57*matchW, 21*matchH)];
    NSLog(@"%f",CGRectGetMinX(self.robotStateL.frame));
    self.robotStateL.text = @"[空闲中]";
    self.robotStateL.font = [UIFont systemFontOfSize:14*matchW];
    self.robotStateL.textAlignment = NSTextAlignmentCenter;
    self.robotStateL.textColor = [RGBColorEncapsulation colorWithRGB:0x0ac8c6 alpha:1];
    [self addSubview:self.robotStateL];
    
    self.robotStateImageV = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.robotStateL.frame) - 22 *matchW, CGRectGetMinY(self.robotStateL.frame), 21*matchW, CGRectGetHeight(self.robotStateL.frame))];
    NSLog(@"%f",self.robotStateImageV.frame.size.height);
    self.robotStateImageV.image = [UIImage imageNamed:@"status_free"];
    [self addSubview:self.robotStateImageV];
    
    self.operationBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    self.operationBtn.frame = CGRectMake(147.5*matchW, CGRectGetMaxY(self.robotStateL.frame) + 38*matchH, 80*matchW, 80*matchH);
    [self.operationBtn setBackgroundImage:[UIImage imageNamed:@"gameboy"] forState:UIControlStateNormal];
    [self addSubview:self.operationBtn];
    
    self.btn_btnView = [[SKBtn_btnEncapsulation alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.operationBtn.frame) - 52*matchW - 50*matchW, CGRectGetMinY(self.operationBtn.frame) + 12*matchH, 52*matchW, 48*matchH) imageName:@"icon_growth" title:@"成长相册"];
    [self addSubview:self.btn_btnView];
    
    self.btn_btnViewSetUp = [[SKBtn_btnEncapsulation alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.operationBtn.frame) + 50*matchW , CGRectGetMinY(self.operationBtn.frame) + 12*matchH, 52*matchW, 48*matchH) imageName:@"icon_set" title:@"设置"];
    [self addSubview:self.btn_btnViewSetUp];
}

@end
